rsrings <- function(pt, numofrings=c(5), clr=FALSE, ...)
{
	if(!is.matrix(pt)) stop ("first argument pt must be a 2 dimensional matrix");
	n=length(pt)/2
	m=n

if(clr==TRUE)
{
 plot(pt[,1],pt[,2],pch=20,xlab='x',ylab='y');
       m1 = .C("rs_depthrings",
                   xpoints=as.double(pt[,1]), 
  		   ypoints=as.double(pt[,2]),
  		   outx=double(m),
  		   outy=double(m),
                   sz=as.integer(m),
                    PACKAGE = "rsdepth");

##don't return the convex hull... start from 2.
numofrings=numofrings+1
	for(i in 2:numofrings)
	{
	
		x=m1$outx[(1+( (i-1)*m/numofrings)):m]
		y=m1$outy[(1+( (i-1)*m/numofrings)):m]
#		print(m1$outx)
#		print(m1$outy)
	
		k=chull(x,y)
		polygon(x[k],y[k])
	}
	points(m1$outx[m],m1$outy[m],pch=20,col="red")
	
	


}
else
{

       m1 = .C("rs_rings",
                   xpoints=as.double(pt[,1]), 
  		   ypoints=as.double(pt[,2]),
  		   ringX=double(m^4),
  		   ringY=double(m^4),  		   
  		   ringszArr=integer(m),
                   sz=as.integer(m),
                   ringsz=as.integer(numofrings),
                   approx=as.integer(c(0)),
                    PACKAGE = "rsdepth");
 
 plot(m1$xpoints,m1$ypoints,pch=20,xlab='x',ylab='y');
 count=1
 cols=c("#43C6DB","#B93B8F","#7F38EC","#C12283","#98AFC7","#8467D7","#3BB9FF" )
 for(i in ( 1:m1$ringsz) )
 {
 
 	xa=m1$ringX[ (count):(count+m1$ringszArr[i]-1) ]; 	
 	xb=m1$ringY[ (count):(count+m1$ringszArr[i]-1) ];
 	#print(xa)
 	#print(xb)
 	k=chull(xa,xb);
 	if(clr)
 	{
 		polygon(xa[k],xb[k],col=cols[i%%7]);
 	}
 	else
 	{
	 	polygon(xa[k],xb[k]);
 	}
 	count=count+m1$ringszArr[i];
 	#print(i)
 	#print(m1$ringsz)
 	
 }
 
 return (m1$ringsz);   
}

}

